#ifndef VIEWSTYLE_H
#define VIEWSTYLE_H

#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif


  class MarginStyle {
    public:
      int style;
      int width;
      int mask;
      bool sensitive;
      int cursor;
      MarginStyle();
  };


  class FontNames {
    private:
      std::vector<char *> names;


      FontNames( const FontNames & );
    public:
      FontNames();
      ~FontNames();
      void Clear();
      const char *Save( const char *name );
  };

  class FontRealised : public FontMeasurements {

      FontRealised( const FontRealised & );
      FontRealised &operator=( const FontRealised & );
    public:
      Font font;
      FontRealised();
      virtual ~FontRealised();
      void Realise( Surface &surface, int zoomLevel, int technology, const FontSpecification &fs );
  };

  enum IndentView {ivNone, ivReal, ivLookForward, ivLookBoth};

  enum WhiteSpaceVisibility {wsInvisible = 0, wsVisibleAlways = 1, wsVisibleAfterIndent = 2};

  typedef std::map<FontSpecification, FontRealised *> FontMap;

  enum WrapMode { eWrapNone, eWrapWord, eWrapChar, eWrapWhitespace };

  class ColourOptional : public ColourDesired {
    public:
      bool isSet;
      ColourOptional( ColourDesired colour_ = ColourDesired( 0, 0, 0 ), bool isSet_ = false ) : ColourDesired( colour_ ), isSet( isSet_ ) {
      }
      ColourOptional( uptr_t wParam, sptr_t lParam ) : ColourDesired( static_cast<long>( lParam ) ), isSet( wParam != 0 ) {
      }
  };

  struct ForeBackColours {
    ColourOptional fore;
    ColourOptional back;
  };


  class ViewStyle {
      FontNames fontNames;
      FontMap fonts;
    public:
      std::vector<Style> styles;
      size_t nextExtendedStyle;
      LineMarker markers[MARKER_MAX + 1];
      int largestMarkerHeight;
      Indicator indicators[INDIC_MAX + 1];
      int technology;
      int lineHeight;
      int lineOverlap;
      unsigned int maxAscent;
      unsigned int maxDescent;
      XYPOSITION aveCharWidth;
      XYPOSITION spaceWidth;
      XYPOSITION tabWidth;
      ForeBackColours selColours;
      ColourDesired selAdditionalForeground;
      ColourDesired selAdditionalBackground;
      ColourDesired selBackground2;
      int selAlpha;
      int selAdditionalAlpha;
      bool selEOLFilled;
      ForeBackColours whitespaceColours;
      int controlCharSymbol;
      XYPOSITION controlCharWidth;
      ColourDesired selbar;
      ColourDesired selbarlight;
      ColourOptional foldmarginColour;
      ColourOptional foldmarginHighlightColour;
      ForeBackColours hotspotColours;
      bool hotspotUnderline;
      bool hotspotSingleLine;

      int leftMarginWidth;
      int rightMarginWidth;
      int maskInLine;
      MarginStyle ms[SC_MAX_MARGIN + 1];
      int fixedColumnWidth;
      bool marginInside;
      int textStart;
      int zoomLevel;
      WhiteSpaceVisibility viewWhitespace;
      int whitespaceSize;
      IndentView viewIndentationGuides;
      bool viewEOL;
      ColourDesired caretcolour;
      ColourDesired additionalCaretColour;
      bool showCaretLineBackground;
      bool alwaysShowCaretLineBackground;
      ColourDesired caretLineBackground;
      int caretLineAlpha;
      ColourDesired edgecolour;
      int edgeState;
      int caretStyle;
      int caretWidth;
      bool someStylesProtected;
      bool someStylesForceCase;
      int extraFontFlag;
      int extraAscent;
      int extraDescent;
      int marginStyleOffset;
      int annotationVisible;
      int annotationStyleOffset;
      bool braceHighlightIndicatorSet;
      int braceHighlightIndicator;
      bool braceBadLightIndicatorSet;
      int braceBadLightIndicator;
      int theEdge;
      int marginNumberPadding;
      int ctrlCharPadding;
      int lastSegItalicsOffset;

      WrapMode wrapState;
      int wrapVisualFlags;
      int wrapVisualFlagsLocation;
      int wrapVisualStartIndent;
      int wrapIndentMode;
      ViewStyle();
      ViewStyle( const ViewStyle &source );
      ~ViewStyle();
      void Init( size_t stylesSize_ = 256 );
      void Refresh( Surface &surface, int tabInChars );
      void ReleaseAllExtendedStyles();
      int AllocateExtendedStyles( int numberStyles );
      void EnsureStyle( size_t index );
      void ResetDefaultStyle();
      void ClearStyles();
      void SetStyleFontName( int styleIndex, const char *name );
      bool ProtectionActive() const;
      int ExternalMarginWidth() const;
      bool ValidStyle( size_t styleIndex ) const;
      void CalcLargestMarkerHeight();
      ColourOptional Background( int marksOfLine, bool caretActive, bool lineContainsCaret ) const;
      bool SelectionBackgroundDrawn() const;
      bool WhitespaceBackgroundDrawn() const;
      ColourDesired WrapColour() const;

      bool SetWrapState( int wrapState_ );
      bool SetWrapVisualFlags( int wrapVisualFlags_ );
      bool SetWrapVisualFlagsLocation( int wrapVisualFlagsLocation_ );
      bool SetWrapVisualStartIndent( int wrapVisualStartIndent_ );
      bool SetWrapIndentMode( int wrapIndentMode_ );

    private:
      void AllocStyles( size_t sizeNew );
      void CreateAndAddFont( const FontSpecification &fs );
      FontRealised *Find( const FontSpecification &fs );
      void FindMaxAscentDescent();

      ViewStyle &operator=( const ViewStyle & );
  };

  #ifdef SCI_NAMESPACE
}
  #endif

#endif
